package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finance.domain.BuyMustPay;
import com.ruoyi.finance.service.IBuyMustPayService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购应付Controller
 * 
 * @author lvql
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/buyMustPay")
public class BuyMustPayController extends BaseController
{
    @Autowired
    private IBuyMustPayService buyMustPayService;

    /**
     * 查询采购应付列表
     */
    @RequiresPermissions("finance:buyMustPay:list")
    @GetMapping("/list")
    public TableDataInfo list(BuyMustPay buyMustPay)
    {
        startPage();
        List<BuyMustPay> list = buyMustPayService.selectBuyMustPayList(buyMustPay);
        return getDataTable(list);
    }
    /*获取可核销的应付单*/
    @RequiresPermissions("finance:buyMustPay:list")
    @GetMapping("/getReconList")
    public TableDataInfo getReconList(BuyMustPay buyMustPay)
    {
        List<BuyMustPay> list = buyMustPayService.getReconList(buyMustPay);
        return getDataTable(list);
    }



    /**
     * 导出采购应付列表
     */
    @RequiresPermissions("finance:buyMustPay:export")
    @Log(title = "采购应付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyMustPay buyMustPay)
    {
        List<BuyMustPay> list = buyMustPayService.selectBuyMustPayList(buyMustPay);
        ExcelUtil<BuyMustPay> util = new ExcelUtil<BuyMustPay>(BuyMustPay.class);
        util.exportExcel(response, list, "采购应付数据");
    }

    /**
     * 获取采购应付详细信息
     */
    @RequiresPermissions("finance:buyMustPay:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(buyMustPayService.selectBuyMustPayById(id));
    }
    /**
     * 获取所有应付金额
     */
    @RequiresPermissions("finance:buyMustPay:query")
    @GetMapping(value = "getAllMustPay")
    public AjaxResult getAllMustPay()
    {
        return success(buyMustPayService.getAllMustPay());
    }
    /**
     * 获取当日采购应付笔数及金额
     * @return
     */
    @RequiresPermissions("finance:buyMustPay:query")
    @GetMapping(value = "getBuyCountAndMoney")
    public AjaxResult getBuyCountAndMoney()
    {
        return success(buyMustPayService.getBuyCountAndMoney());
    }

    /**
     * 获取当日销售退货应付笔数及金额
     * @return
     */
    @RequiresPermissions("finance:buyMustPay:query")
    @GetMapping(value = "getPaySaleBackCountAndMoney")
    public AjaxResult getPaySaleBackCountAndMoney()
    {
        return success(buyMustPayService.getSaleBackCountAndMoney());
    }
    /**
     * 新增采购应付
     */
    @RequiresPermissions("finance:buyMustPay:add")
    @Log(title = "采购应付", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyMustPay buyMustPay)
    {
        return toAjax(buyMustPayService.insertBuyMustPay(buyMustPay));
    }

//    @RequiresPermissions("finance:buyMustPay:add")
    @InnerAuth
    @Log(title = "采购应付", businessType = BusinessType.INSERT)
    @PostMapping("/innerAdd")
    public R<Boolean> innerAdd(@RequestBody BuyMustPay buyMustPay)
    {
        logger.info("BuyMustPayController innerAdd params {}", buyMustPay.toString());
        return R.ok(buyMustPayService.insertBuyMustPay(buyMustPay)>0);
    }

    /**
     * 修改采购应付
     */
    @RequiresPermissions("finance:buyMustPay:edit")
    @Log(title = "采购应付", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyMustPay buyMustPay)
    {
        return toAjax(buyMustPayService.updateBuyMustPay(buyMustPay));
    }

    /**
     * 删除采购应付
     */
    @RequiresPermissions("finance:buyMustPay:remove")
    @Log(title = "采购应付", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(buyMustPayService.deleteBuyMustPayByIds(ids));
    }
}
